package com.qeegoo.b2bautozityp.moudle.goods.viewmodel;

//┏┓　　　┏┓ 
//┏┛┻━━━┛┻┓ 
//┃　　　　　　　┃ 　 
//┃　　　━　　　┃ 
//┃　┳┛　┗┳　┃ 
//┃　　　　　　　┃ 
//┃　　　┻　　　┃ 
//┃　　　　　　　┃ 
//┗━┓　　　┏━┛ 
//┃　　　┃  神兽保佑　　　　　　　　 
//┃　　　┃  代码无BUG！ 
//┃　　　┗━━━┓ 
//┃　　　　　　　┣┓ 
//┃　　　　　　　┏┛ 
//┗┓┓┏━┳┓┏┛ 
// ┃┫┫　┃┫┫ 
// ┗┻┛　┗┻┛

import android.databinding.ObservableField;
import android.support.v4.view.PagerAdapter;

import com.kelin.mvvmlight.command.ReplyCommand;
import com.qeegoo.b2bautozityp.adapter.ImagePagerAdapter;
import com.qeegoo.b2bautozityp.api.HttpParams;
import com.qeegoo.b2bautozityp.api.ProgressSubscriber;
import com.qeegoo.b2bautozityp.api.RequestApi;
import com.qeegoo.b2bautozityp.api.RetrofitService;
import com.qeegoo.b2bautozityp.moudle.goods.model.GoodsDetailResult;

import java.util.List;

/**
 * Created by lk on 2017/9/20.
 */

public class GoodsDetailViewModel {
    private final RequestApi requestApi;
    private List<GoodsDetailResult.GoodsImage> imageList;
    public ObservableField<PagerAdapter> viewpagerAdapter = new ObservableField();
    public ObservableField<String> imageIndex = new ObservableField("");
    public ObservableField<String> goodsCount = new ObservableField();
    public ObservableField<String> goodsInfo = new ObservableField();
    public ObservableField<String> unitPriceNoInvoice = new ObservableField();
    public ObservableField<String> settlePriceNoInvoice = new ObservableField();
    public ObservableField<String> tradePriceNoInvoice = new ObservableField();
    public ObservableField<String> unitPrice = new ObservableField();
    public ObservableField<String> tradePrice = new ObservableField();
    public ObservableField<String> settlePrice = new ObservableField();

    public ObservableField<String> goodsCode = new ObservableField();
    public ObservableField<String> goodsOE = new ObservableField();
    public ObservableField<String> goodsBrand = new ObservableField();
    public ObservableField<String> goodsStyle = new ObservableField();
    public ObservableField<String> goodsCategory = new ObservableField();
    public ObservableField<String> goodsMarks = new ObservableField();
    public ObservableField<String> goodsOfAutozi = new ObservableField();
    public ObservableField<String> goodsProductAdd = new ObservableField();

    public ObservableField<String> detailUrl = new ObservableField();


    public ReplyCommand<Integer> onPageSelectedCommand = new ReplyCommand<Integer>(pos ->{
        imageIndex.set(pos+1+"/"+imageList.size());
    });
    public GoodsDetailViewModel(RequestApi requestApi) {

        this.requestApi = requestApi;
    }

    public void getData(String goodId) {

        requestApi.detailGoods(HttpParams.paramDetailById(goodId))
                .map(new RetrofitService.HttpResultFunc<>())
                .compose(RetrofitService.applySchedulers())
                .subscribe(new ProgressSubscriber<GoodsDetailResult>() {
                    @Override
                    public void onNext(GoodsDetailResult goodsDetailResult) {
                        imageList = goodsDetailResult.listImg;
                        viewpagerAdapter.set(new ImagePagerAdapter(goodsDetailResult.listImg));
                        goodsCount.set("库存"+goodsDetailResult.goods.quantity+"件");
                        goodsInfo.set(goodsDetailResult.goods.name);
                        unitPriceNoInvoice.set(goodsDetailResult.goods.unitPriceNoInvoice);
                        settlePriceNoInvoice.set(goodsDetailResult.goods.settlePriceNoInvoice);
                        tradePriceNoInvoice.set(goodsDetailResult.goods.tradePriceNoInvoice);
                        unitPrice.set(goodsDetailResult.goods.unitPrice);
                        tradePrice.set(goodsDetailResult.goods.tradePrice);
                        settlePrice.set(goodsDetailResult.goods.settlePrice);
                        goodsCode.set(goodsDetailResult.goods.id);
                        goodsOE.set(goodsDetailResult.goods.oemCode);
                        goodsBrand.set(goodsDetailResult.goods.brandName);
                        goodsStyle.set(goodsDetailResult.goods.packageStyle);
                        goodsCategory.set(goodsDetailResult.goods.productType);
                        goodsMarks.set(goodsDetailResult.goods.goodsRemark);
                        goodsOfAutozi.set(goodsDetailResult.goods.partyName);
                        goodsProductAdd.set(goodsDetailResult.goods.areaName);
                        detailUrl.set(goodsDetailResult.goods.goodsDetails);
                        imageIndex.set("1/"+imageList.size());
                    }
                });



    }
}
